home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Texteditors / Origami / Sources / src / origami / buffloop.c next >
Encoding:
C/C++ Source or Header  |  1996-09-27  |  47.8 KB  |  1,157 lines

  1. /*{{{}}}*/
  2. /*{{{  #includes*/
  3. #ifdef CONFIG_H
  4. #   include "config.h"
  5. #endif
  6.  
  7. #include <sys/types.h>
  8. #include <limits.h>
  9. #include <unistd.h>
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #include <string.h>
  13.  
  14. #define BUFFLOOP_C
  15. #define I_DISPLAY_C
  16. #define I_FIELDEDIT_C
  17. #define I_FINDS_C
  18. #define I_FOLDHELP_C
  19. #define I_FOLDFILING_C
  20. #define I_FOLDING_C
  21. #define I_FOLDFILING_C
  22. #define I_GETMSG_C
  23. #define I_GETTK_C
  24. #define I_KEYBOARD_C
  25. #define I_KEYTAB_C
  26. #define I_LOOP_C
  27. #define I_MAIN_C
  28. #define I_MISC_C
  29. #define I_MESSAGES_C
  30. #define I_ORIEDT_C
  31. #define I_PROMPT_C
  32. #define I_READFOLDS_C
  33. #define I_SCREEN_C
  34. #define I_SHELL_C
  35. #define I_SIGNALS_C
  36. #define I_STRING_C
  37. #define I_VIRTUAL_C
  38. #define I_WRITEF_C
  39.  
  40. #include "origami.h"
  41. #include <lib/ori_add_lib.h>
  42. /*}}}  */
  43.  
  44. /*{{{  variables*/
  45. public element *deleted_lines[UNDEL_LINES];
  46. public int delete_ptr=0;
  47. #ifdef REGEXP
  48.   public reg_types reg_type=no_reg;
  49. #endif
  50. /*}}}  */
  51.  
  52. /*{{{  try_unchange*/
  53. public void try_unchange(void)
  54. {
  55.   if (bd.m.file_changed_status==changed_once)
  56.    { bd.m.file_changed_status=unchanged_file;
  57.      title_op(CHGTITLE);
  58.    }
  59. }
  60. /*}}}  */
  61. /*{{{  buffer_loop*/
  62. /*{{{  ref_shifted_line*/
  63. private void ref_shifted_line(void)
  64. {
  65.   if (bd.scr.cur_shift_w!=bd.scr.full_shift_w)
  66.    /*{{{  line is shifted left, unshift it*/
  67.    { write_dsp_line(bd.f.current,bd.scr.cursor.h);
  68.      bd.scr.cur_shift_w=bd.scr.full_shift_w;
  69.    }
  70.    /*}}}  */
  71. }
  72. /*}}}  */
  73.  
  74. TOKEN buffer_loop(TOKEN ch,boolean active_buffer)
  75. {
  76.   if (bd.m.upd_sel_delayed && !scr_off)
  77.      upd_highlight(bd.f.real_head,bd.f.real_tail,True);
  78.   switch (ch)
  79.    {
  80.      /*{{{  O_NOP: a normal editor loop*/
  81.      case O_NOP:
  82.       { boolean quit;
  83.  
  84.         title_op(CHGTITLE);
  85.         /*{{{  set ocl vars for screen and screen position..*/
  86.         ocl_var[var_cu_b_id].v=bd.scr.id;
  87.         ocl_var[var_cu_buff].v=bd.scr.list_no;
  88.         ocl_var[var_scr_h].v=bd.scr.txt_size.h;
  89.         ocl_var[var_off_h].v=bd.scr.off.h;
  90.         ocl_var[var_scr_w].v=bd.scr.txt_size.w;
  91.         ocl_var[var_off_w].v=bd.scr.off.w;
  92.         ocl_var[var_file_no].v=bd.e.file_no;
  93.         /*}}}  */
  94.         for (quit=False,ch=O_NOP;!quit;)
  95.          {
  96.            /*{{{  variables*/
  97.            int old_x;
  98.            int scr_key;
  99.            /*}}}  */
  100.  
  101.            /*{{{  save screen-cursor x-position to ocl-var*/
  102.            ocl_var[cy_ind].v=bd.scr.cursor.h;
  103.            old_x=bd.scr.cursor.w;
  104.            /*}}}  */
  105.            /*{{{  maybe change window title*/
  106. #           ifdef WINDOW_TITLE_CHANGE
  107.               if (wt_buff_id!=bd.scr.id && !scr_off)
  108.                { chg_w_title((char*)0);
  109.                  wt_buff_id=bd.scr.id;
  110.                }
  111. #           endif
  112.            /*}}}  */
  113.            /*{{{  maybe warn about multiple edited buffer*/
  114.            if (mult_edit)
  115.             { ori_assert(bd.scr.cur_shift_w<=LINELEN*max_dsp,"shift-check");
  116.               title_op(PRTTITLE);
  117.               message(get_msg(M_MULT_EDIT,mult_edit+1));
  118.               mult_edit=0;
  119.               if (!scr_off) warn_delay();
  120.             }
  121.            /*}}}  */
  122.            /*{{{  maybe full redraw screen if long message or interrupt_restore*/
  123.            if (interrupt_restore || (dirty && ch!=O_PROMPT))
  124.              { B_invalid();
  125.                auto_flush();
  126.              }
  127.            /*}}}  */
  128.            /*{{{  handle abort*/
  129.            if (aborted)
  130.             { aborted = False;
  131.               if (!run_abort_mac)
  132.                { stop_macros(True);
  133.                  call_number_macro(abort_macro);
  134.                  run_abort_mac=True;
  135.                }
  136.               else
  137.                  run_abort_mac=False;
  138.               if (!ocl_screen_on())
  139.                { while (!ocl_screen_on());
  140.                  auto_flush();
  141.                }
  142.               msg_message(M_ABORTED);
  143.             }
  144.            /*}}}  */
  145.            /*{{{  get textline, call fieldedit, save textline*/
  146.            copyin(cur_dsp_line, bd.f.current, False);
  147.            bd.f.cur_line_typ=get_linetyp(*bd.f.current);
  148.            /*{{{  get next editor-token*/
  149.            ch=field_edit();
  150.            /*}}}  */
  151.            ori_assert(bd.f.cur_line_typ==get_linetyp(*bd.f.current),"check cur_linetyp");
  152.            if (!(bd.f.cur_line_typ&END_FOLD))
  153.               copyout(cur_dsp_line, bd.f.current);
  154.            /*}}}  */
  155.            /*{{{  maybe execute command here*/
  156.            ori_assert(bd.scr.cur_shift_w<=LINELEN*max_dsp,"shift-check");
  157.            switch ((scr_key=valid_screen_key(ch)))
  158.             {
  159.               /*{{{  0 : error, no [restricted]fold key*/
  160.               no_restricted_fold_key:
  161.                  upd_highlight(bd.f.real_head,bd.f.real_tail,True);
  162.               case 0:
  163.                  msg_message(M_NOFOLDKEY);
  164.                  break;
  165.               /*}}}  */
  166.               /*{{{  +/- 1 : (un) limited fold key*/
  167.               case -1:
  168.                /*{{{  reset highlight marks*/
  169.                { sel_mod old_h;
  170.  
  171.                  old_h=bd.m.select_mode;
  172.                  bd.m.select_mode=no_selection;
  173.                  upd_highlight(bd.f.real_head,bd.f.real_tail,True);
  174.                  bd.m.select_mode=old_h;
  175.                }
  176.                /*}}}  */
  177.               case 1:
  178.                /*{{{  handle action*/
  179.                  if (ch!=O_PROMPT) no_message();
  180.                  if (ch>=O_NOP)
  181.                   /*{{{  handle loop command*/
  182.                   { switch (ch) {
  183.                      /*{{{  default: no action*/
  184.                      no_highlight_redraw:
  185.                      default:
  186.                         scr_key= -2;
  187.                         break;
  188.                      /*}}}  */
  189.                      /*{{{  ops, handled partial in main loop*/
  190.                      case M_SHOW_HELP:
  191.                         set_area(ocl_var[get_arg("area-size")].v);
  192.                         ch=O_REFRESH;
  193.                      case O_A_NOPARSE:
  194.                      case O_D_NOPARSE:
  195.                      case O_A_AUTO_SAVE:
  196.                      case O_D_AUTO_SAVE:
  197.                      case O_DESCRIBE_BINDINGS:
  198.                      case O_DSP:
  199.                      case O_HELP:
  200.                      case O_OPEN_BUFFER:
  201.                      case O_OPEN_W_BUFFER:
  202.                      case O_OPEN_LIST_BUFFER:
  203.                      case O_OPEN_LIST_W_BUFFER:
  204.                      case O_GROW_BUFFER:
  205.                      case O_GROW_W_BUFFER:
  206.                      case O_SHRINK_BUFFER:
  207.                      case O_SHRINK_W_BUFFER:
  208.                      case O_AUTO_SAVE:
  209.                      case O_FLUSH:
  210.                      case O_REFRESH:
  211.                      case O_TITLE_HIDE:
  212.                      case O_TITLE_SHOW:
  213.                      case M_LAYOUT:
  214.                      case M_GO_BUFFER:
  215.                          quit=True;
  216.                          goto no_highlight_redraw;
  217.                      /*}}}  */
  218. #                    ifdef REGEXP
  219.                       /*{{{  reg exp handling*/
  220.                       /*{{{  O_D_REGEXP*/
  221.                         case O_D_REGEXP:
  222.                            if (reg_type)
  223.                             { ocl_var[var_ocl_arg].v=(reg_type==basic_reg)?1:2;
  224.                               reg_type=no_reg;
  225.                               title_op(CHGTITLE);
  226.                             }
  227.                            else
  228.                               ocl_var[var_ocl_arg].v=0;
  229.                            break;
  230.                       /*}}}  */
  231.                       /*{{{  O_A_B_REGEXP*/
  232.                         case O_A_B_REGEXP:
  233.                            if (reg_type!=basic_reg)
  234.                             { reg_type=basic_reg;
  235.                               ocl_var[var_ocl_arg].v=1;
  236.                               title_op(CHGTITLE);
  237.                             }
  238.                            break;
  239.                       /*}}}  */
  240.                       /*{{{  O_A_REGEXP*/
  241.                         case O_A_X_REGEXP:
  242.                            if (reg_type!=ext_reg)
  243.                             { reg_type=ext_reg;
  244.                               ocl_var[var_ocl_arg].v=2;
  245.                               title_op(CHGTITLE);
  246.                             }
  247.                            break;
  248.                       /*}}}  */
  249.                       /*}}}  */
  250. #                    else
  251.                       /*{{{  reg exp not here*/
  252.                         case O_D_REGEXP:
  253.                         case O_A_B_REGEXP:
  254.                         case O_A_X_REGEXP:
  255.                            ocl_var[var_ocl_arg].v=0;
  256.                            message(M_NOT_HERE);
  257.                            break;
  258.                       /*}}}  */
  259. #                    endif
  260.                      /*{{{  M_EDIT_HISTORY*/
  261.                      case M_EDIT_HISTORY:
  262.                       { unsigned char prompt[LINELEN + 1];
  263.                         unsigned char ret[LINELEN + 1];
  264.                         histories old_default;
  265.                         unsigned char const *init_text;
  266.                         int init_pos;
  267.  
  268.                         /*{{{  get initialization for the prompt*/
  269.                         switch (get_arg("hist edit init"))
  270.                          { case 0:
  271.                            default:
  272.                               init_text=0;
  273.                               init_pos= -1;
  274.                               break;
  275.                            case 1:
  276.                               init_text=cur_dsp_line;
  277.                               init_pos=bd.scr.cursor.w-2;
  278.                               break;
  279.                            case 2:
  280.                               init_text=(bd.f.real_tail==bd.f.real_head)
  281.                                          ? 0
  282.                                          : get_data(bd.f.real_tail);
  283.                               init_pos= -1;
  284.                               break;
  285.                          }
  286.                         /*}}}  */
  287.                         old_default=overwrite_history_id;
  288.                         overwrite_history_id=(histories)get_arg("history");
  289.                         prompt_string(prompt);
  290.                         readprompt
  291.                          ( ret,
  292.                            prompt,
  293.                            LINELEN,
  294.                            overwrite_history_id,
  295.                            init_text,
  296.                            init_pos
  297.                          );
  298.                         overwrite_history_id=old_default;
  299.                         break;
  300.                       }
  301.                      /*}}}  */
  302.                      /*{{{  M_WRITE_HELP*/
  303.                      case M_WRITE_HELP:
  304.                       { int x;
  305.                         int y;
  306.                         unsigned char pr[LINELEN+1];
  307.  
  308.                         x=ocl_var[get_arg("area-x")].v;
  309.                         y=ocl_var[get_arg("area-y")].v;
  310.                         prompt_string(pr);
  311.                         write_area(x,y,pr);
  312.                         break;
  313.                       }
  314.                      /*}}}  */
  315.                      /*{{{  M_CHANGE_FOLD*/
  316.                      case M_CHANGE_FOLD:
  317.                       { int t=get_arg("fold-type");
  318.  
  319.                         if (chg_foldtype(ocl_var[t].v,ocl_var[get_arg("fold-contents")].v))
  320.                          { unchange_error_po:
  321.  
  322.                            try_unchange();
  323.  
  324.                            error_po:
  325.  
  326.                            verbose_msg_message(M_ERR_PO);
  327.                          }
  328.                         goto no_highlight_redraw;
  329.                       }
  330.                      /*}}}  */
  331.                      /*{{{  O_ATTACH_FILE*/
  332.                      case O_ATTACH_FILE:
  333.                         attach_file();
  334.                         goto no_highlight_redraw;
  335.                      /*}}}  */
  336.                      /*{{{  O_A_POSI*/
  337.                      case O_A_POSI:
  338.                         if (!xy_show)
  339.                          { xy_show=True;
  340.                            title_op(CHGTITLE);
  341.                          }
  342.                         goto no_highlight_redraw;
  343.                      /*}}}  */
  344.                      /*{{{  O_A_ECHO*/
  345.                      case O_A_ECHO:
  346.                         switch_echo(True);
  347.                         message((unsigned char*)STR_E_A);
  348.                         goto no_highlight_redraw;
  349.                      /*}}}  */
  350.                      /*{{{  O_A_TIME*/
  351.                      case O_A_TIME:
  352.                         switch_time(True);
  353.                         goto no_highlight_redraw;
  354.                      /*}}}  */
  355.                      /*{{{  O_A_VERBOSE*/
  356.                      case O_A_VERBOSE:
  357.                         verbose=True;
  358.                         message((unsigned char*)STR_V_A);
  359.                         goto no_highlight_redraw;
  360.                      /*}}}  */
  361.                      /*{{{  O_A_FULLSHIFT*/
  362.                      case O_A_FULLSHIFT:
  363.                         init_buffer.m.full_shift=bd.m.full_shift=True;
  364.                         message((unsigned char*)STR_F_A);
  365.                         goto no_highlight_redraw;
  366.                      /*}}}  */
  367.                      /*{{{  O_BOT_OF_FOLD*/
  368.                      case O_BOT_OF_FOLD:
  369.                         ref_shifted_line();
  370.                         skip_to(bd.f.tail);
  371.                         break;
  372.                      /*}}}  */
  373.                      /*{{{  O_BREAK*/
  374.                      case O_BREAK:
  375.                         break;
  376.                      /*}}}  */
  377.                      /*{{{  O_CHANGE_MARK*/
  378.                      case O_CHANGE_MARK:
  379.                         chg_marks();
  380.                         break;
  381.                      /*}}}  */
  382.                      /*{{{  O_CLOSE_FOLD*/
  383.                      case O_CLOSE_FOLD:
  384.                         close_fold();
  385.                         break;
  386.                      /*}}}  */
  387.                      /*{{{  O_COPY*/
  388.                      case O_COPY:
  389.                       { element  *copy_ptr;
  390.  
  391.                         ori_assert(bd.f.cur_line_typ==get_linetyp(*bd.f.current),"check cur_linetyp");
  392.                         if
  393.                          (    (bd.f.cur_line_typ&(NOT_FOLD|START_FOLD|START_FILED))
  394.                            && bd.f.current!=bd.f.tail
  395.                            && (copy_ptr=copy_a_line())
  396.                          )
  397.                          { ref_shifted_line();
  398.                            undel_after(copy_ptr);
  399.                          }
  400.                         else
  401.                            goto unchange_error_po;
  402.                         break;
  403.                       }
  404.                      /*}}}  */
  405.                      /*{{{  O_COPY_PICK*/
  406.                      case O_COPY_PICK:
  407.                         ori_assert(bd.f.cur_line_typ==get_linetyp(*bd.f.current),"check cur_linetyp");
  408.                         if (bd.f.cur_line_typ&(NOT_FOLD|START_FOLD|START_FILED))
  409.                            append_to_pick(copy_a_line());
  410.                         else
  411.                            goto error_po;
  412.                         break;
  413.                      /*}}}  */
  414.                      /*{{{  O_CREATE_FOLD*/
  415.                      case O_CREATE_FOLD:
  416.                         switch (bd.m.select_mode)
  417.                          { case no_selection:
  418.                             /*{{{  start fold or highlight*/
  419.                               switch (ocl_var[var_mod_beh].v)
  420.                                { case fold_selection-1:
  421.                                  case unmark_fold_selection-1:
  422.                                   /*{{{  start folding*/
  423.                                     ori_assert(bd.f.cur_line_typ==get_linetyp(*bd.f.current),"check cur_linetyp");
  424.                                     if (bd.f.cur_line_typ&(START_ENTER_FOLD|START_ENTER_FILED))
  425.                                        goto unchange_error_po;
  426.                                     else
  427.                                      { start_make_fold(ocl_var[var_mod_beh].v+1);
  428.                                        title_op
  429.                                         ( bd.f.count_comment_line
  430.                                            ? CHGXY
  431.                                            : INCY
  432.                                         );
  433.                                      }
  434.                                     break;
  435.                                   /*}}}  */
  436.                                  case lim_pseudo_fold_selection-1:
  437.                                   /*{{{  lim_pseudo-fold-selection*/
  438.                                     bd.m.select_mode=lim_pseudo_fold_selection;
  439.                                     goto do_start_select;
  440.                                   /*}}}  */
  441.                                  case lim_reg_selection-1:
  442.                                   /*{{{  limited region selection*/
  443.                                     bd.m.select_mode=lim_reg_selection;
  444.                                     goto do_start_select;
  445.                                   /*}}}  */
  446.                                  case lim_block_selection-1:
  447.                                   /*{{{  limited block selection*/
  448.                                     bd.m.select_mode=lim_block_selection;
  449.                                     goto do_start_select;
  450.                                   /*}}}  */
  451.                                  case lim_nodrawn_selection-1:
  452.                                   /*{{{  limited nodrawn selection*/
  453.                                     bd.m.select_mode=lim_nodrawn_selection;
  454.                                     goto do_start_select;
  455.                                   /*}}}  */
  456.                                  case -(lim_pseudo_fold_selection-1):
  457.                                   /*{{{  pseudo-fold-selection*/
  458.                                     bd.m.select_mode=pseudo_fold_selection;
  459.                                     goto do_start_select;
  460.                                   /*}}}  */
  461.                                  case -(lim_reg_selection-1):
  462.                                   /*{{{  unlimited region selection*/
  463.                                     bd.m.select_mode=reg_selection;
  464.                                     goto do_start_select;
  465.                                   /*}}}  */
  466.                                  case -(lim_block_selection-1):
  467.                                   /*{{{  unlimited block selection*/
  468.                                     bd.m.select_mode=block_selection;
  469.                                     goto do_start_select;
  470.                                   /*}}}  */
  471.                                  case -(lim_nodrawn_selection-1):
  472.                                   /*{{{  unlimited nodrawn selection*/
  473.                                     bd.m.select_mode=nodrawn_selection;
  474.                                     goto do_start_select;
  475.                                   /*}}}  */
  476.                                  do_start_select:
  477.                                    /*{{{  start highlighting*/
  478.                                    bd.f.select_ptr=bd.f.current;
  479.                                    bd.e.makefold_indent=bd.scr.cursor.w-1;
  480.                                    upd_highlight(bd.f.current,bd.f.current,False);
  481.                                    if
  482.                                     (    bd.m.select_mode==lim_pseudo_fold_selection
  483.                                       || bd.m.select_mode==pseudo_fold_selection
  484.                                     ) move_down();
  485.                                    break;
  486.                                    /*}}}  */
  487.                                  default:
  488.                                     break;
  489.                                }
  490.                               break;
  491.                             /*}}}  */
  492.                            case fold_selection:
  493.                            case unmark_fold_selection:
  494.                             /*{{{  try to make a fold*/
  495.                               make_fold();
  496.                               if (bd.m.select_mode==no_selection)
  497.                                  title_op(CHGXY);
  498.                               break;
  499.                             /*}}}  */
  500.                            default:
  501.                             /*{{{  end highlighting*/
  502.                               bd.m.select_mode=no_selection;
  503.                               upd_highlight(bd.f.real_head,bd.f.real_tail,True);
  504.                               restore(1);
  505.                               break;
  506.                             /*}}}  */
  507.                          }
  508.                         break;
  509.                      /*}}}  */
  510.                      /*{{{  O_DEL_LINE*/
  511.                      case O_DEL_LINE:
  512.                       { element *x;
  513.                         int op=delete_ptr;
  514.                       
  515.                         ref_shifted_line();
  516.                         if (++delete_ptr==UNDEL_LINES) delete_ptr=0;
  517.                         x=deleted_lines[delete_ptr];
  518.                         remove_line(&deleted_lines[delete_ptr]);
  519.                         if (x==deleted_lines[delete_ptr])
  520.                          { delete_ptr=op;
  521.                       
  522.                      unchange_file:
  523.                       
  524.                            try_unchange();
  525.                          }
  526.                         break;
  527.                       }
  528.                      /*}}}  */
  529.                      /*{{{  O_DELETE*/
  530.                      case O_DELETE:
  531.                         ori_assert(bd.f.cur_line_typ==get_linetyp(*bd.f.current),"check cur_linetyp");
  532.                         if
  533.                          (    (bd.f.cur_line_typ&NOT_FOLD)
  534.                            && bd.f.current != bd.f.tail
  535.                            && bd.f.current != bd.f.head->next
  536.                            && test_linetyp
  537.                                ( *(bd.f.current->prec),
  538.                                  (   NOT_FOLD
  539.                                    | START_FILED
  540.                                    | START_FOLD
  541.                                    | START_OPEN_FOLD
  542.                                    | START_ENTER_FOLD
  543.                                  )
  544.                                )
  545.                          )
  546.                          { title_op(CHGXY);
  547.                            ustrcpy(line_buffer,get_data(bd.f.current));
  548.                            trailing_spaces(line_buffer);
  549.                            bd.f.cur_line_typ=get_linetyp(*bd.f.current);
  550.                            move_up();
  551.                            copyin(cur_dsp_line, bd.f.current, False);
  552.                            trailing_spaces(cur_dsp_line);
  553.                            bd.scr.cursor.w=txt2scr(bd.f.enter_spaces,
  554.                                                    ustrlen(cur_dsp_line),
  555.                                                    cur_dsp_line);
  556.                            if (bd.scr.cursor.w==1)
  557.                               bd.scr.cursor.w=bd.f.current->indent+1;
  558.                            if
  559.                             (    (ustrlen(line_buffer)+ustrlen(cur_dsp_line))
  560.                               <= LINELEN-bd.f.enter_spaces
  561.                             )
  562.                             { ustrcpy(cur_dsp_line,get_data(bd.f.current));
  563.                               ustrcat(cur_dsp_line,line_buffer);
  564.                               set_data
  565.                                ( bd.f.current,cur_dsp_line,
  566.                                  test_linetyp(*bd.f.current,NOT_FOLD)
  567.                                );
  568.                               ori_assert((cur_dsp_line[0]==0)||((cur_dsp_line[ustrlen(cur_dsp_line)-1]!='\t')&&(cur_dsp_line[ustrlen(cur_dsp_line)-1]!=' ')),"delete-join: trailling space");
  569.                               write_dsp_line(bd.f.current, bd.scr.cursor.h);
  570.                               bd.f.cur_line_typ=get_linetyp(*bd.f.current);
  571.                               move_down();
  572.                               bd.e.part_line = 0;
  573.                               remove_line(&bd.e.part_line);
  574.                               proc_dispose(bd.e.part_line);
  575.                               bd.f.cur_line_typ=get_linetyp(*bd.f.current);
  576.                               move_up();
  577.                               break;
  578.                             }
  579.                            else
  580.                               msg_message(M_LONG_LINE);
  581.                          }
  582.                         else
  583.                            verbose_msg_message(M_ERR_PO);
  584.                         goto unchange_file;
  585.                      /*}}}  */
  586.                      /*{{{  O_D_POSI*/
  587.                      case O_D_POSI:
  588.                         if (xy_show)
  589.                          { xy_show=False;
  590.                            title_op(CHGTITLE);
  591.                          }
  592.                         goto no_highlight_redraw;
  593.                      /*}}}  */
  594.                      /*{{{  O_D_ECHO*/
  595.                      case O_D_ECHO:
  596.                         switch_echo(False);
  597.                         message((unsigned char*)STR_E_D);
  598.                         goto no_highlight_redraw;
  599.                      /*}}}  */
  600.                      /*{{{  O_D_TIME*/
  601.                      case O_D_TIME:
  602.                         ocl_var[var_ocl_arg].v=switch_time(False);
  603.                         goto no_highlight_redraw;
  604.                      /*}}}  */
  605.                      /*{{{  O_D_VERBOSE*/
  606.                      case O_D_VERBOSE:
  607.                         verbose=False;
  608.                         message((unsigned char*)STR_V_D);
  609.                         goto no_highlight_redraw;
  610.                      /*}}}  */
  611.                      /*{{{  O_D_FULLSHIFT*/
  612.                      case O_D_FULLSHIFT:
  613.                         ocl_var[var_ocl_arg].v=bd.m.full_shift?1:0;
  614.                         init_buffer.m.full_shift=bd.m.full_shift=False;
  615.                         message((unsigned char*)STR_F_D);
  616.                         goto no_highlight_redraw;
  617.                      /*}}}  */
  618.                      /*{{{  O_DOWN*/
  619.                      case O_DOWN:
  620.                         ref_shifted_line();
  621.                         move_down();
  622.                         break;
  623.                      /*}}}  */
  624.                      /*{{{  O_ENTER_FOLD*/
  625.                      case O_ENTER_FOLD:
  626.                         if (scr_key<=0) goto no_restricted_fold_key;
  627.                         enter_fold((unsigned char*)0);
  628.                         goto chg_file_no;
  629.                      /*}}}  */
  630.                      /*{{{  O_ENTER_NO_FILE*/
  631.                      case O_ENTER_NO_FILE:
  632.                         if (scr_key<=0) goto no_restricted_fold_key;
  633.                         enter_list_file();
  634.                         goto chg_file_no;
  635.                      /*}}}  */
  636.                      /*{{{  O_EXIT_FOLD*/
  637.                      case O_EXIT_FOLD:
  638.                         if (scr_key<=0) goto no_restricted_fold_key;
  639.                         bd.scr.cursor.w = 1;
  640.                         exit_fold();
  641.                         goto chg_file_no;
  642.                      /*}}}  */
  643.                      /*{{{  O_FILE_FOLD*/
  644.                      case O_FILE_FOLD:
  645.                         file_fold((unsigned char*)0,(FILE*)0);
  646.                         goto no_highlight_redraw;
  647.                      /*}}}  */
  648.                      /*{{{  O_FILTER_OPs*/
  649.                      case O_FILTER_BUFFER:
  650.                      case O_FILTER_LINE:
  651.                         if (scr_key<=0)
  652.                            goto no_restricted_fold_key;
  653.                         filter_op(ch==O_FILTER_BUFFER);
  654.                         break;
  655.                      /*}}}  */
  656.                      /*{{{  O_FIND/O_FIND_REVERSE*/
  657.                      case O_FIND:
  658.                      case O_FIND_REVERSE:
  659.                         ref_shifted_line();
  660.                         get_search(False,False,True);
  661.                         if (*item_to_look_for != '\0' && !aborted)
  662.                          { if
  663.                             ( !find_item
  664.                                 ( (ch==O_FIND_REVERSE),
  665.                                   True,
  666.                                   True
  667.                                   re_args(reg_type)
  668.                                 )
  669.                             )
  670.                               msg_message(M_FAILED);
  671.                            title_op(CHGXY);
  672.                          }
  673.                         break;
  674.                      /*}}}  */
  675.                      /*{{{  M/O_FINISH*/
  676.                      case M_FINISH:
  677.                      case O_FINISH:
  678.                         check_time_event();
  679.                         save_file(True);
  680.                         ori_assert(bd.scr.cur_shift_w<=LINELEN*max_dsp,"shift-check");
  681.                         title_op(PRTTITLE);
  682.                         if (bd.m.file_changed_status==unchanged_file)
  683.                            quit=True;
  684.                         else
  685.                            auto_flush();
  686.                         break;
  687.                      /*}}}  */
  688.                      /*{{{  O_FIRST_LINE_TO_FOLD_H*/
  689.                      case O_FIRST_LINE_TO_FOLD_H:
  690.                         ori_assert(bd.f.cur_line_typ==get_linetyp(*bd.f.current),"check cur_linetyp");
  691.                         if (!(bd.f.cur_line_typ&(START_FOLD|START_OPEN_FOLD)))
  692.                            goto unchange_error_po;
  693.                         set_data(bd.f.current,get_data(bd.f.current->x.fold.data),False);
  694.                         write_dsp_line(bd.f.current, bd.scr.cursor.h);
  695.                         goto no_highlight_redraw;
  696.                      /*}}}  */
  697.                      /*{{{  O_FOLD_INFO*/
  698.                      case O_FOLD_INFO:
  699.                         print_buffer[0]='[';
  700.                         /*{{{  position and current char*/
  701.                         { int txt_pos;
  702.                           int curr_c;
  703.  
  704.                           copyin(cur_dsp_line, bd.f.current, False);
  705.                           txt_pos=scr2txt(bd.f.enter_spaces,bd.scr.cursor.w,cur_dsp_line);
  706.                           curr_c=(txt_pos>=ustrlen(cur_dsp_line))?' ':cur_dsp_line[txt_pos];
  707.                           ustrcpy(print_buffer+1,
  708.                                   get_msg(F_INFO_1,
  709.                                           cur_line_no(),
  710.                                           bd.scr.cursor.w+bd.f.enter_spaces,
  711.                                           curr_c,
  712.                                           curr_c,
  713.                                           curr_c,
  714.                                           curr_c,
  715.                                           bd.f.entered,
  716.                                           bd.f.enter_spaces));
  717.                         }
  718.                         /*}}}  */
  719.                         /*{{{  filename and type/contents*/
  720.                         { unsigned char *f=(unsigned char*)empty_text;
  721.  
  722.                           ori_assert(bd.f.cur_line_typ==get_linetyp(*bd.f.current),"check cur_linetyp");
  723.                           switch (bd.f.cur_line_typ)
  724.                            { case END_FOLD:
  725.                                 if (test_linetyp(*(bd.f.current->x.fold.other_end),START_ENTER_FILED))
  726.                                    f=get_data(bd.f.current);
  727.                                 else if (0)
  728.                              case START_FILED:
  729.                              case START_ENTER_FILED:
  730.                                  { f=get_data(bd.f.current->x.fold.other_end);
  731.                                    add_history(file_history,f);
  732.                                  }
  733.                              case START_FOLD:
  734.                              case START_OPEN_FOLD:
  735.                              case START_ENTER_FOLD:
  736.                               /*{{{  get string*/
  737.                                 ustrcat
  738.                                  ( print_buffer,
  739.                                    get_msg
  740.                                     ( F_INFO_2,
  741.                                       bd.f.current->x.fold.UU.U1.type,
  742.                                       bd.f.current->x.fold.UU.U1.contents,
  743.                                       f
  744.                                     )
  745.                                  );
  746.                                 trailing_spaces(print_buffer);
  747.                               /*}}}  */
  748.                               /*{{{  set ocl-arg to coding type/contents*/
  749.                                 ocl_var[var_ocl_arg].v=
  750.                                     ((bd.f.current->x.fold.UU.U1.type&127)<<8)
  751.                                   + bd.f.current->x.fold.UU.U1.contents;
  752.                                 if (bd.f.current->x.fold.UU.U1.type&128)
  753.                                    ocl_var[var_ocl_arg].v= -ocl_var[var_ocl_arg].v;
  754.                               /*}}}  */
  755.                              default:
  756.                                 break;
  757.                            }
  758.                         }
  759.                         /*}}}  */
  760.                         ustrcat(print_buffer,(unsigned char*)"]");
  761.                         message(print_buffer);
  762.                         ch=O_PROMPT;
  763.                         break;
  764.                      /*}}}  */
  765.                      /*{{{  O_GOTO_LINE*/
  766.                      case O_GOTO_LINE:
  767.                         goto_line(-1,(element*)0,False);
  768.                         break;
  769.                      /*}}}  */
  770.                      /*{{{  M_GOTO_MARK*/
  771.                      case M_GOTO_MARK:
  772.                         goto_line
  773.                          ( 0,
  774.                            ocl_var[get_arg("go-mark-arg")].l,
  775.                            ocl_var[var_mod_beh].v
  776.                          );
  777.                         break;
  778.                      /*}}}  */
  779.                      /*{{{  O_INSERT_FILE*/
  780.                      case O_INSERT_FILE:
  781.                         ori_assert(bd.f.cur_line_typ==get_linetyp(*bd.f.current),"check cur_linetyp");
  782.                         if (bd.f.cur_line_typ&(START_ENTER_FOLD|START_ENTER_FILED))
  783.                            goto unchange_error_po;
  784.                         else
  785.                          { struct lg_dumb lang_dump;
  786.  
  787.                            save_lang(&lang_dump);
  788.                            insert_file
  789.                             ( (element *)0,
  790.                               bd.f.current->prec,
  791.                               bd.f.current,
  792.                               False,
  793.                               bd.f.real_head,
  794.                               (boolean*)0,
  795.                               (boolean*)0,
  796.                               (FILE*)0
  797.                             );
  798.                            reset_lang(&lang_dump);
  799.                            bd.m.read_only=False;
  800.                            title_op(CHGXY);
  801.                            restore_element(bd.scr.cursor.h);
  802.                          }
  803.                         break;
  804.                      /*}}}  */
  805.                      /*{{{  O_ITS_REVERSE*/
  806.                      case O_ITS_REVERSE:
  807.                         ref_shifted_line();
  808.                         its_search(True);
  809.                         break;
  810.                      /*}}}  */
  811.                      /*{{{  O_ITS_SEARCH*/
  812.                      case O_ITS_SEARCH:
  813.                         ref_shifted_line();
  814.                         its_search(False);
  815.                         break;
  816.                      /*}}}  */
  817.                      /*{{{  O_LANGUAGE*/
  818.                      case O_LANGUAGE:
  819.                         proc_language();
  820.                         goto no_highlight_redraw;
  821.                      /*}}}  */
  822.                      /*{{{  O_MOVE*/
  823.                      case O_MOVE:
  824.                       { static element *move_ptr=0;
  825.  
  826.                         if (move_ptr)
  827.                          { ori_assert(bd.f.cur_line_typ==get_linetyp(*bd.f.current),"check cur_linetyp");
  828.                            if (bd.f.cur_line_typ&(START_ENTER_FOLD|START_ENTER_FILED))
  829.                               goto unchange_error_po;
  830.                            else
  831.                             { ref_shifted_line();
  832.                               undel_before(move_ptr);
  833.                               move_ptr = 0;
  834.                             }
  835.                          }
  836.                         else
  837.                            remove_line(&move_ptr);
  838.                         ocl_var[var_move_count].v=move_ptr?1:0;
  839.                         break;
  840.                       }
  841.                      /*}}}  */
  842.                      /*{{{  O_OPEN_FOLD*/
  843.                      case O_OPEN_FOLD:
  844.                         open_fold();
  845.                         break;
  846.                      /*}}}  */
  847.                      /*{{{  O_OPEN_NEW_FILE*/
  848.                      case O_OPEN_NEW_FILE:
  849.                         if (scr_key<=0) goto no_restricted_fold_key;
  850.                         open_file(False);
  851.                         goto chg_file_no;
  852.                      /*}}}  */
  853.                      /*{{{  O_OPEN_LIST_FILE*/
  854.                      case O_OPEN_LIST_FILE:
  855.                         if (scr_key<=0) goto no_restricted_fold_key;
  856.                         open_list_file();
  857.                         goto chg_file_no;
  858.                      /*}}}  */
  859.                      /*{{{  O_PAGE_UP/DOWN*/
  860.                      case O_PAGE_DOWN:
  861.                       { int i;
  862.  
  863.                         ref_shifted_line();
  864.                         i=bd.scr.txt_size.h-bd.scr.cursor.h+1;
  865.                         /*{{{  skip i lines*/
  866.                         while (i-- && bd.f.current != bd.f.tail)
  867.                            bd.f.current = bd.f.current->next;
  868.                         /*}}}  */
  869.                         goto o_p_refresh;
  870.                      case O_PAGE_UP:
  871.                         ref_shifted_line();
  872.                         i=bd.scr.txt_size.h+bd.scr.cursor.h-3;
  873.                         /*{{{  skip i lines*/
  874.                         while (i-- && bd.f.current->prec != bd.f.head)
  875.                            bd.f.current = bd.f.current->prec;
  876.                         /*}}}  */
  877.                      o_p_refresh:
  878.                         title_op(CHGXY);
  879.                         if (bd.m.select_mode!=no_selection)
  880.                            upd_highlight(bd.f.real_head,bd.f.real_tail,True);
  881.                         restore_element(1);
  882.                         break;
  883.                       }
  884.                      /*}}}  */
  885.                      /*{{{  O_PICK*/
  886.                      case O_PICK:
  887.                       { element  *pick_ptr;
  888.  
  889.                         pick_ptr = 0;
  890.                         remove_line(&pick_ptr);
  891.                         if (pick_ptr)
  892.                            append_to_pick(pick_ptr);
  893.                         else
  894.                            try_unchange();
  895.                         goto no_highlight_redraw;
  896.                       }
  897.                      /*}}}  */
  898.                      /*{{{  O_PIPE_FROM_COMMAND*/
  899.                      case O_PIPE_FROM_COMMAND:
  900.                         ori_assert(bd.f.cur_line_typ==get_linetyp(*bd.f.current),"check cur_linetyp");
  901.                         if (bd.f.cur_line_typ&(START_ENTER_FOLD|START_ENTER_FILED))
  902.                            goto unchange_error_po;
  903.                         else
  904.                          { pipe_from_command();
  905.                            restore_element(bd.scr.cursor.h);
  906.                          }
  907.                         break;
  908.                      /*}}}  */
  909.                      /*{{{  O_PIPE_TO_COMMAND*/
  910.                      case O_PIPE_TO_COMMAND:
  911.                         if (bd.f.tail == bd.f.real_tail)
  912.                            pipe_to_command();
  913.                         else
  914.                            msg_message(M_NO_TOP);
  915.                         goto no_highlight_redraw;
  916.                      /*}}}  */
  917.                      /*{{{  O_PROMPT*/
  918.                      case O_PROMPT:
  919.                         write_dsp_line(bd.f.current,bd.scr.cursor.h);
  920.                         if (executing_macro) oflush;
  921.                         break;
  922.                      /*}}}  */
  923.                      /*{{{  O_PUT_PICK*/
  924.                      case O_PUT_PICK:
  925.                         ori_assert(bd.f.cur_line_typ==get_linetyp(*bd.f.current),"check cur_linetyp");
  926.                         if (bd.f.cur_line_typ&(START_ENTER_FOLD|START_ENTER_FILED))
  927.                            goto unchange_error_po;
  928.                         else if (pick_head != pick_tail)
  929.                            undel_pick_before();
  930.                         else
  931.                          { msg_message(M_NO_PICK);
  932.                            goto unchange_file;
  933.                          }
  934.                         break;
  935.                      /*}}}  */
  936.                      /*{{{  O_QUERY_REPLACE*/
  937.                      case O_QUERY_REPLACE:
  938.                         if (scr_key<=0) goto no_restricted_fold_key;
  939.                         ref_shifted_line();
  940.                         query_replace(False);
  941.                         break;
  942.                      /*}}}  */
  943.                      /*{{{  O_QUIT*/
  944.                      case O_QUIT:
  945.                         check_time_event();
  946.                         ori_assert(bd.scr.cur_shift_w<=LINELEN*max_dsp,"shift-check");
  947.                         title_op(PRTTITLE);
  948.                         quit = (bd.m.file_changed_status!=unchanged_file ?
  949.                                      yes(get_msg(M_CHANGED_LEAVE)) : True);
  950.                         break;
  951.                      /*}}}  */
  952.                      /*{{{  O_REMOVE_FOLD*/
  953.                      case O_REMOVE_FOLD:
  954.                         unfold();
  955.                         break;
  956.                      /*}}}  */
  957.                      /*{{{  O_RENAME_FILE*/
  958.                      case O_RENAME_FILE:
  959.                         if (bd.f.real_tail!=bd.f.real_head)
  960.                          { unsigned char file[_POSIX_PATH_MAX+1];
  961.  
  962.                            fileprompt(file);
  963.                            if (file[0])
  964.                             { set_data(bd.f.real_tail,file,False);
  965.                               set_data(bd.f.real_head->next,file,False);
  966.                               add_edit_file((char*)0,cur_line_no(),True);
  967.                               bd.e.file_no=add_edit_file((char*)file,cur_line_no(),True);
  968.                               bd.m.dir_edit=is_dir((FILE*)0,(char*)file);
  969. #                             ifdef WINDOW_TITLE_CHANGE
  970.                                  wt_buff_id= -1;
  971. #                             endif
  972.                               title_op(CHGTITLE);
  973.                               restore_element(bd.scr.cursor.h);
  974.                               warn_mult_edit();
  975.                      chg_file_no:
  976.                               ocl_var[var_file_no].v=bd.e.file_no;
  977.                               break;
  978.                             }
  979.                          }
  980.                         goto no_highlight_redraw;
  981.                      /*}}}  */
  982.                      /*{{{  O_REPLACE*/
  983.                      case O_REPLACE:
  984.                         if (scr_key<=0) goto no_restricted_fold_key;
  985.                         do_replace();
  986.                         break;
  987.                      /*}}}  */
  988.                      /*{{{  O_RETURN*/
  989.                      case O_RETURN:
  990.                         switch (bd.m.select_mode)
  991.                          { case no_selection:
  992.                            case pseudo_fold_selection:
  993.                            case reg_selection:
  994.                            case block_selection:
  995.                               ref_shifted_line();
  996.                               if (bd.e.split_line)
  997.                                  undel_after(bd.e.part_line);
  998.                               else
  999.                                { undel_before(bd.e.part_line);
  1000.                                  bd.f.cur_line_typ=get_linetyp(*bd.f.current);
  1001.                                  move_down();
  1002.                                }
  1003.                            default:
  1004.                               break;
  1005.                          }
  1006.                         break;
  1007.                      /*}}}  */
  1008.                      /*{{{  O_SAVE_FILE*/
  1009.                      case O_SAVE_FILE:
  1010.                         save_file(False);
  1011.                         goto no_highlight_redraw;
  1012.                      /*}}}  */
  1013.                      /*{{{  O_SHELL_COMMAND*/
  1014.                      case O_SHELL_COMMAND:
  1015.                       { unsigned char cmd[LINELEN + 1];
  1016.  
  1017.                         s_readprompt(cmd, get_msg(M_SH_COMMAND), LINELEN,shell_history);
  1018.                         if (*cmd)
  1019.                          { TOKEN x;
  1020.  
  1021.                            put_vars();
  1022.                            reset_keyboard();
  1023.                            reset_terminal();
  1024.                            force_sh=ocl_var[var_force_sh].v;
  1025.                            ocl_var[var_ocl_arg].v=subshell((char*)cmd);
  1026.                            init_terminal();
  1027.                            init_keyboard();
  1028.                            B_valid();
  1029.                            msg_message(M_END);
  1030.                            do
  1031.                             { x=hide_key(); }
  1032.                            while (x!=O_RETURN && x!=O_BREAK);
  1033.                            B_invalid();
  1034.                            auto_flush();
  1035.                          }
  1036.                         goto no_highlight_redraw;
  1037.                       }
  1038.                      /*}}}  */
  1039.                      /*{{{  O_SHELL*/
  1040.                      case O_SHELL:
  1041.                         msg_message(M_SHELL_CREATED);
  1042.                         put_vars();
  1043.                         reset_keyboard();
  1044.                         reset_terminal();
  1045.                         force_sh=ocl_var[var_force_sh].v;
  1046.                         subshell((char*)0);
  1047.                         init_terminal();
  1048.                         init_keyboard();
  1049.                         B_invalid();
  1050.                         auto_flush();
  1051.                         goto no_highlight_redraw;
  1052.                      /*}}}  */
  1053.                      /*{{{  O_SUSPEND*/
  1054.                      case O_SUSPEND:
  1055.                         suspend();
  1056.                         goto no_highlight_redraw;
  1057.                      /*}}}  */
  1058.                      /*{{{  O_TOP_OF_FOLD*/
  1059.                      case O_TOP_OF_FOLD:
  1060.                         ref_shifted_line();
  1061.                         skip_to(bd.f.head->next);
  1062.                         break;
  1063.                      /*}}}  */
  1064.                      /*{{{  O_UNDEL_LINE*/
  1065.                      case O_UNDEL_LINE:
  1066.                         ori_assert(bd.f.cur_line_typ==get_linetyp(*bd.f.current),"check cur_linetyp");
  1067.                         if (bd.f.cur_line_typ&(START_ENTER_FOLD|START_ENTER_FILED))
  1068.                            goto unchange_error_po;
  1069.                         else if (deleted_lines[delete_ptr])
  1070.                          { ref_shifted_line();
  1071.                            undel_before(deleted_lines[delete_ptr]);
  1072.                            deleted_lines[delete_ptr] = 0;
  1073.                            if (--delete_ptr<0)
  1074.                               delete_ptr=UNDEL_LINES-1;
  1075.                          }
  1076.                         else
  1077.                          { msg_message(M_NO_UNDEL);
  1078.                            goto unchange_file;
  1079.                          }
  1080.                         break;
  1081.                      /*}}}  */
  1082.                      /*{{{  O_UP*/
  1083.                      case O_UP:
  1084.                         ref_shifted_line();
  1085.                         move_up();
  1086.                         break;
  1087.                      /*}}}  */
  1088.                      /*{{{  O_WRITE_FILE*/
  1089.                      case O_WRITE_FILE:
  1090.                         write_file();
  1091.                         goto no_highlight_redraw;
  1092.                      /*}}}  */
  1093.                     }
  1094.                   }
  1095.                   /*}}}  */
  1096.                /*}}}  */
  1097.                /*{{{  maybe reset highlight marks*/
  1098.                  if (scr_key<0)
  1099.                   { ori_assert(bd.scr.cur_shift_w<=LINELEN*max_dsp,"shift-check");
  1100.                     upd_highlight(bd.f.real_head,bd.f.real_tail,True);
  1101.                     ori_assert(bd.scr.cur_shift_w<=LINELEN*max_dsp,"shift-check");
  1102.                     if (scr_key>-2)
  1103.                        restore(1);
  1104.                   }
  1105.                /*}}}  */
  1106.                  break;
  1107.               /*}}}  */
  1108.             }
  1109.            if
  1110.             /*{{{  block-selection changed*/
  1111.             (    scr_key>=1
  1112.               && old_x!=bd.scr.cursor.w
  1113.               && (    bd.m.select_mode==lim_block_selection
  1114.                    || bd.m.select_mode==block_selection
  1115.                  )
  1116.             )
  1117.             /*}}}  */
  1118.             /*{{{  redraw display for new marks*/
  1119.               restore(1);
  1120.             /*}}}  */
  1121.            /*}}}  */
  1122.          }
  1123.         break;
  1124.       }
  1125.      /*}}}  */
  1126.      /*{{{  O_AUTO_SAVE*/
  1127.      case O_AUTO_SAVE:
  1128.         auto_write();
  1129.         break;
  1130.      /*}}}  */
  1131.      /*{{{  O_REFRESH/O_FLUSH*/
  1132.      case O_REFRESH:
  1133.         if (active_buffer)
  1134.          { bd.scr.cur_shift_w=0;
  1135.            title_op(CHGXY);
  1136.            restore_element(bd.scr.txt_size.h / 2);
  1137. #          ifdef WINDOW_TITLE_CHANGE
  1138.               if (!scr_off)
  1139.                  wt_buff_id= -1;
  1140. #          endif
  1141.            break;
  1142.          }
  1143.      case O_FLUSH:
  1144.         if (bd.scr.txt_size.h)
  1145.            restore_element(bd.scr.cursor.h);
  1146.         if (!active_buffer)
  1147.            title_op(SMALLTITLE);
  1148.         break;
  1149.      /*}}}  */
  1150.      default:
  1151.         ch=O_NOP;
  1152.         break;
  1153.    }
  1154.   return(ch);
  1155. }
  1156. /*}}}  */
  1157.